-- CONSTANTES -- TITULOS E ENDEREÇOS DE IMAGENS

NOME_MENU =	"<BR><BR><BR><BR>     SELECIONE A OPERACAO"
NOME_PLACA = "<BR><BR><BR><BR>   ESTACIONAMENTO ROTATIVO"
NOME_PTO = "<BR><BR><BR><BR>SELECIONE O MODO DE PAGAMENTO"
NOME_CONFIRMA = "<BR><BR><BR><BR> VERIFICAR E CONFIRMAR"
NOME_LOGIN = "<BR><BR><BR><BR>           USUARIO"
NOME_DINHEIRO = "<BR><BR><BR><BR>           DINHEIRO"
NOME_SEM_CACHE = "<BR><BR><BR><BR>   CACHE DESATUALIZADO"
NOME_ERRO_CACHE = "<BR><BR><BR><BR>         ERRO"

IMG_BG = "background-widescreen.bmp"
IMG_ESTACIO = "logoEstaciotec.bmp"
IMG_WAF = "logoWAF.bmp"

IMG_OP_1 = "choose-operation-option-1-pt.bmp"
IMG_XOP_2 = "xchoose-operation-option-2-pt.bmp"
IMG_XOP_3 = "xchoose-operation-option-3-pt.bmp"
IMG_XOP_42 = "Xchoose-operation-option-42-pt.bmp"

IMG_PTO_1 = "choose-method-1.bmp"
IMG_PTO_2 = "choose-method-2.bmp"
IMG_PTO_3 = "choose-method-3.bmp"
IMG_PTO_4 = "choose-method-4.bmp"

IMG_CON_YES = "choose-yes-logout-pt.bmp"
IMG_CON_NO = "choose-no-logout-pt.bmp"

IMG_LINE = "line-insert-only-pin.bmp"

-- CONTROLE DA FUNÇÃO DE POR IMAGEM NA TELA -- CASO DEVA LIMPAR A TELA OU NÃO 

LIMPA = 1
NAO_LIMPA = 0


function Call_Module(...)
	
	echo ("<data destination=parser>\r\n")
	echo ("	dofile(\"waf.lua\")")
	
	for i, v in ipairs(arg) do
		if i==1 then
			if table.getn(arg)==1 then
				echo ("	"..arg[1].."()")
			else
				echo ("	"..arg[1].."(")
			end
		elseif i>1 then
			if i<table.getn(arg) then
				echo (""..arg[i]..",")
			elseif i==table.getn(arg) then
				echo (""..arg[i]..")")
			end
		end
	end
	echo ("</data>")
	
end

function ImagemTela(imagem, x, y, limpa)
	
	if(limpa==LIMPA) then echo ("<CONSOLE></CONSOLE>") end
	echo("<CONLOGO NAME="..imagem.." X="..x.."  Y="..y..">")
	
end

function TxtTela(...)
	
	echo ("<CONSOLE NOCLS=0>")
	for i, v in ipairs(arg) do
	echo(""..arg[i].."")
	end
	echo ("</CONSOLE>")
	
end



------------------------------------------

function Teste()-------------
	
	-- escreve em um txt-------------------
	echo ("<CONSOLE></CONSOLE>")-------------------
	TxtTela("<BR>Escrever<BR>")--------------------------
	file = io.open("test.txt", "w+")------------------------------
	io.output(file)-----------------------------
	t=io.write("Teste")------------------------------
	io.close(file)------------------------------------
	
	
	
	-- le um txt----------------------------------
	TxtTela("<BR>ler<BR>")-----------------------------
	file = io.open("test.txt", "r")-------------------------------
	io.input(file)-------------------------
	t=io.read("*all")---------------------------
	io.close(file)------------------------
	TxtTela("<BR>"..t.."<BR>")--------------------------
	
	
	--os.remove(test.txt)-----------------------------------------
	
end
-------------------------------------------------------------------------------------


function Limpa()
	
		os.remove("test.txt")
		os.remove("login.txt")
		os.remove("cache.txt")
	
	echo ("<CONSOLE></CONSOLE")
	echo ("<CONSOLE> <BR> Limpo <BR ></CONSOLE>")
	
end

------------------------------------------------------------Login-------------------------------------------------------
function TrocaLogin()
	
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	ImagemTela(IMG_LINE, 65, 182, NAO_LIMPA)
	
	TxtTela("<BR><BR><BR><BR>     CONFIGURACAO USUARIO", "<BR><BR><BR>   DIGITE A SENHA DE ACESSO")
	
	echo ("<GET TYPE=PASS NAME=SENHA SIZE=6 COL=9 LIN=11=>")
	
	Call_Module("SenhaLogin")
	
end

function SenhaLogin()

	ImagemTela(IMG_BG, 0, 0, LIMPA)
	
	get = loadstring(GET)()
	sen = get["SENHA"]
	
	if(sen == "166831") then
		LoginAcesso()
	else
		TxtTela("<BR><BR><BR><BR>     CONFIGURACAO USUARIO", "<BR><BR><BR><BR><BR>      SENHA INVALIDA!")
		echo ("<GET TYPE=ANYKEY>")
	end
	Inicio()
	
end

function LoginAcesso()
	
	GetLogin()
	
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	
	TxtTela(NOME_LOGIN, "<BR><BR><BR> ATUAL: "..usu.."", " <BR><BR><BR><BR>        DESEJA ALTERAR?")
	
	ImagemTela(IMG_CON_YES, 17, 220, NAO_LIMPA)
	ImagemTela(IMG_CON_NO, 126, 220, NAO_LIMPA)
	
	echo ("<RECTANGLE NAME=SIM X=17  Y=220 WIDTH=97 HEIGHT=45 VISIBLE=0>")
	echo ("<RECTANGLE NAME=NAO X=126  Y=220 WIDTH=97 HEIGHT=45 VISIBLE=0>")
	echo ("<CAPTURE NAME=TROCA>")
	echo ("<GET TYPE=TOUCH>")
	--echo ("<GET TYPE=SPECIALKEY>")
	echo ("</CAPTURE>")
	
	Call_Module("TrocaLoginResp")
	
end

function TrocaLoginResp()
	
	get = loadstring(GET)()
	troca = get["TROCA"]
		
	if(troca == "SIM") then
		os.remove("login.txt")
		Login()
	else
		Inicio()
	end
	
end

function Login()

	ImagemTela(IMG_ESTACIO, 0, 0, LIMPA)
	TxtTela("<BR><BR> VERIFICANDO USUARIO...")
	
	
	
	file = io.open("login.txt", "r")
	
	if file == nil then 
		file = io.open("login.txt", "w+")
		io.output(file)
		t=io.write("usuario-0,pass-0")
		io.close(file)
		
		file = io.open("login.txt", "r")
	end
	io.input(file)
	t=io.read("*all") 
	io.close(file) 
		
	passID = string.find(t,",")
	usu = string.sub(t, 9, passID-1)
	pass = string.sub(t, passID+6)
	
	if(usu == "0" and pass == "0") then
		NovoUsuario()
	else 
		Cache()
	end	
end

function GetLogin()
	
	file = io.open("login.txt", "r")
	io.input(file)
	t=io.read("*all") 
	io.close(file) 
	
	passID = string.find(t,",")
	usu = string.sub(t, 9, passID-1)
	pass = string.sub(t, passID+6)
	
end

function NovoUsuario()
	
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	ImagemTela(IMG_LINE, 65, 182, NAO_LIMPA)
	TxtTela(NOME_LOGIN, "<BR><BR><BR>        NOVO USUARIO:")
	echo ("<GET TYPE=FIELD ALPHA=1 NAME=USU SIZE=15 COL=9 LIN=11 NOENTER=1>")
	Call_Module("NovaSenha");		
	
end

function NovaSenha()
	
	get = loadstring(GET)()
	usu = get["USU"]
	
	echo ("<GET TYPE=HIDDEN NAME=USU VALUE="..usu..">")
	
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	ImagemTela(IMG_LINE, 65, 182, NAO_LIMPA)
	TxtTela(NOME_LOGIN, "<BR><BR><BR>          SENHA:")
	echo ("<GET TYPE=FIELD ALPHA=1 NAME=SEN SIZE=15 COL=9 LIN=11 NOENTER=1>")
	Call_Module("SalvaLogin");		
	
end

function SalvaLogin()
	
	get = loadstring(GET)()
	usu = get["USU"]
	sen = get["SEN"]
	
	file = io.open("login.txt", "w+")
	io.output(file)
	t=io.write("usuario-"..usu..",pass-"..sen.."")
	io.close(file)
	
	Cache()
	
end
-------------------------------------------------------------------Cache-------------------------------------------------------------------
function Cache()

	ImagemTela(IMG_WAF, 0, 0, LIMPA)
	TxtTela("<BR><BR> ATUALIZANDO CACHE...")
	
	file = io.open("cache.txt", "r")
	
	--FakeCache()--------------------------------------
	
	if file == nil then 
		AtualizaCache() --Recebe Cache
	end
	Inicio()
	
end

-- function FakeCache()----------------------------------
	
	-- file = io.open("cache.txt", "w*")------------------------------
	-- io.output(file)-----------------------------
	-- t=io.write("1-IdentityName-2-IdentityType-3-IdentityId-4-Username-5-PIN-6-PosDeviceId-7-PosDeviceHardwareUniqueId-8-ShopName-9-TicketPrice-10-PriceOfFineCancellation-11-ServiceBaseUrl")------------------------------
	-- io.close(file)------------------------------------
	
-- end-------------------------------

function AtualizaCache()

	ImagemTela(IMG_WAF, 0, 0, LIMPA)
	TxtTela("<BR><BR> ATUALIZANDO CACHE...")

	GetLogin()
	
	echo ("<GET TYPE=HIDDEN NAME=Operation VALUE=updateCache>")
	
	echo ("<GET TYPE=SERIALNO NAME=PosSerial>")
	echo ("<GET TYPE=HIDDEN NAME=Username VALUE="..usu..">")
	echo ("<GET TYPE=HIDDEN NAME=PIN VALUE="..pass..">")
	
	echo ("<GET TYPE=HIDDEN NAME=Funcao VALUE=RecebeCache>")
	
	
	echo ("<POST>")
	
	-- --------------------------Testes-apartir-daqui-favor-deletar--------------------------------------------------------
	-- new = 50
	
	-- echo ("<GET TYPE=HIDDEN NAME=chIdentityName VALUE="..new..">")-------------
	-- echo ("<GET TYPE=HIDDEN NAME=chIdentityType VALUE="..new..">")-------------
	-- echo ("<GET TYPE=HIDDEN NAME=chIdentityId VALUE="..new..">")--------------
	-- echo ("<GET TYPE=HIDDEN NAME=chUsername VALUE="..new..">")--------------------
	-- echo ("<GET TYPE=HIDDEN NAME=chPIN VALUE="..new..">")---------------
	-- echo ("<GET TYPE=HIDDEN NAME=chPosDeviceId VALUE="..new..">")--------------------
	-- echo ("<GET TYPE=HIDDEN NAME=chPosDeviceHardwareUniqueId VALUE="..new..">")------------
	-- echo ("<GET TYPE=HIDDEN NAME=chShopName VALUE="..new..">")-------------
	-- echo ("<GET TYPE=HIDDEN NAME=chTicketPrice VALUE="..new..">")------------
	-- echo ("<GET TYPE=HIDDEN NAME=chPriceOfFineCancellation VALUE="..new..">")------------------
	-- echo ("<GET TYPE=HIDDEN NAME=chServiceBaseUrl VALUE="..new..">")------------------
	-- RecebeCache()---------------------
	
	-- -----------------------------------------------------------------------------
	
end

function RecebeCache()
	
	get = loadstring(GET)()
	
	erro = get["Error"]
	
	IdentityName = get["chIdentityName"]
	IdentityType = get["chIdentityType"]
	IdentityId = get["chIdentityId"]
	Username = get["chUsername"]
	PIN = get["chPIN"]
	PosDeviceId = get["chPosDeviceId"]
	PosDeviceHardwareUniqueId = get["chPosDeviceHardwareUniqueId"]
	ShopName = get["chShopName"]
	TicketPrice = get["chTicketPrice"]
	PriceOfFineCancellation = get["chPriceOfFineCancellation"]
	ServiceBaseUrl = get["chServiceBaseUrl"]
	
	ServiceBaseUrl = url_decode(ServiceBaseUrl) -- Protege o url caso venha caracteres especiais em forma exaDecimal (": - %3A, / - %2F")
	
	cacheStr = IdentityName.."-IdentityName-"
	cacheStr = cacheStr..IdentityType.."-IdentityType-"
	cacheStr = cacheStr..IdentityId.."-IdentityId-"
	cacheStr = cacheStr..Username.."-Username-"
	cacheStr = cacheStr..PIN.."-PIN-"
	cacheStr = cacheStr..PosDeviceId.."-PosDeviceId-"
	cacheStr = cacheStr..PosDeviceHardwareUniqueId.."-PosDeviceHardwareUniqueId-"
	cacheStr = cacheStr..ShopName.."-ShopName-"
	cacheStr = cacheStr..TicketPrice.."-TicketPrice-"
	cacheStr = cacheStr..PriceOfFineCancellation.."-PriceOfFineCancellation-"
	cacheStr = cacheStr..ServiceBaseUrl.."-ServiceBaseUrl-"
	
	if(erro == "1") then
		ErroCache()
	end
	
	file = io.open("cache.txt", "w+")
	io.output(file)
	--t=io.write("1-IdentityName-2-IdentityType-3-IdentityId-4-Username-5-PIN-6-PosDeviceId-7-PosDeviceHardwareUniqueId-8-ShopName-9-TicketPrice-10-PriceOfFineCancellation-11-ServiceBaseUrl")

	if(cacheStr ~= nil) then t=io.write(cacheStr) end

	io.close(file)
		
	Inicio()
	
end

function url_decode(str)
  str = string.gsub (str, "+", " ")
  str = string.gsub (str, "%%(%x%x)",
      function(h) return string.char(tonumber(h,16)) end)
  str = string.gsub (str, "\r\n", "\n")
  return str
end

function ErroCache()
	
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	
	TxtTela(NOME_ERRO_CACHE, "<BR><BR><BR> "..erro.."")
	
	--echo("<DELAY TIME=3>")
	
	echo ("<GET TYPE=SPECIALKEY>")
	
	Inicio()
	
end

function TrataCache()
	
	file = io.open("cache.txt", "r")
	
	if file == nil then CacheDesatualizado() end
	
	io.input(file)
	t=io.read("*all")
	io.close(file)
	
	IdentityName_id = string.find(t,"-IdentityName-")
	IdentityType_id = string.find(t,"-IdentityType-")
	IdentityId_id = string.find(t,"-IdentityId-")
	Username_id = string.find(t,"-Username-")
	PIN_id = string.find(t,"-PIN-")
	PosDeviceId_id = string.find(t,"-PosDeviceId-")
	PosDeviceHardwareUniqueId_id = string.find(t,"-PosDeviceHardwareUniqueId-")
	ShopName_id = string.find(t,"-ShopName-")
	TicketPrice_id = string.find(t,"-TicketPrice-")
	PriceOfFineCancellation_id = string.find(t,"-PriceOfFineCancellation-")
	ServiceBaseUrl_id = string.find(t,"-ServiceBaseUrl-")
	
	IdentityName = string.sub(t, 1, IdentityName_id-1)
	IdentityType = string.sub(t, IdentityName_id+14, IdentityType_id-1)
	IdentityId = string.sub(t, IdentityType_id+14, IdentityId_id-1)
	Username = string.sub(t, IdentityId_id+12, Username_id-1)
	PIN = string.sub(t, Username_id+10, PIN_id-1)
	PosDeviceId = string.sub(t, PIN_id+5, PosDeviceId_id-1)
	PosDeviceHardwareUniqueId = string.sub(t, PosDeviceId_id+13, PosDeviceHardwareUniqueId_id-1)
	ShopName = string.sub(t, PosDeviceHardwareUniqueId_id+27, ShopName_id-1)
	TicketPrice = string.sub(t, ShopName_id+10, TicketPrice_id-1)
	PriceOfFineCancellation = string.sub(t, TicketPrice_id+13, PriceOfFineCancellation_id-1)
	ServiceBaseUrl = string.sub(t, PriceOfFineCancellation_id+25, ServiceBaseUrl_id-1)
	
	--TxtTela("<BR>IdentityName: ", IdentityName,
	--		"<BR>IdentityType: ", IdentityType,
	--		"<BR>IdentityId: ", IdentityId,
	--		"<BR>Username: ", Username,
	--		"<BR>PIN: ", PIN,
	--		"<BR>PosDeviceId: ", PosDeviceId,
	--		"<BR>PosDeviceUniqueId: ", PosDeviceHardwareUniqueId,
	--		"<BR>ShopName: ", ShopName,
	--		"<BR>TicketPrice: ", TicketPrice,
	--		"<BR>PriceOfFineCancellation: ", PriceOfFineCancellation,
	--		"<BR>ServiceBaseUrl: ", ServiceBaseUrl)-----------------------------
	
end

function ExibeCache()
	
	echo ("<CONSOLE></CONSOLE")
	
	TxtTela("<BR>IdentityName: ", IdentityName,
			"<BR>IdentityType: ", IdentityType,
			"<BR>IdentityId: ", IdentityId,
			"<BR>Username: ", Username,
			"<BR>PIN: ", PIN,
			"<BR>PosDeviceId: ", PosDeviceId,
			"<BR>PosDeviceUniqueId: ", PosDeviceHardwareUniqueId,
			"<BR>ShopName: ", ShopName,
			"<BR>TicketPrice: ", TicketPrice,
			"<BR>PriceOfFineCancellation: ", PriceOfFineCancellation,
			"<BR>ServiceBaseUrl: ", ServiceBaseUrl)
			
	echo ("<GET TYPE=SPECIALKEY>")
	
	Inicio()
	
end

-----------------------------------------------------------Programa--------------------------------------------------------------------------
function Inicio()
	
	fileCache = io.open("cache.txt", "r")
	if fileCache == nil then CacheDesatualizado() end
		
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	
	TxtTela(NOME_MENU)
	
	ImagemTela(IMG_OP_1, 17, 125, NAO_LIMPA)
	ImagemTela(IMG_XOP_2, 126, 125, NAO_LIMPA)
	ImagemTela(IMG_XOP_3, 17, 184, NAO_LIMPA)
	ImagemTela(IMG_XOP_42, 126, 184, NAO_LIMPA)

	echo ("<RECTANGLE NAME=TICKET X=17  Y=125 WIDTH=97 HEIGHT=45 VISIBLE=0>")
	echo ("<CAPTURE NAME=ESCOLHA_OP>")
	echo ("<GET TYPE=TOUCH>")
	--echo ("<GET TYPE=SPECIALKEY>")
	echo ("<GET TYPE=FIELD SIZE=1 COL=9 LIN=21 NOENTER=1>")
	echo ("</CAPTURE>")
	
	
	Call_Module("Menu");
	
end

function Menu()

	get = loadstring(GET)()
	op = get["ESCOLHA_OP"]
	
	if(op == "TICKET") then
		LerPlaca()
	elseif(op == "9") then
		TrocaLogin()
	--elseif(op == "0") then
		--Limpa()
		--Login()
	--elseif(op == "1") then
		--TrataCache()
		--ExibeCache()
	--else
		--Inicio()
	end	
	Inicio()

end

function LerPlaca()
	
	echo ("<GET TYPE=HIDDEN NAME=OPERATION VALUE="..op..">")
		
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	ImagemTela(IMG_LINE, 65, 182, NAO_LIMPA)
	
	TxtTela(NOME_PLACA, "<BR><BR><BR>       DIGITE A PLACA")
	
	echo ("<GET TYPE=FIELD ALPHA=1 NAME=PLACA SIZE=7 COL=9 LIN=11 NOENTER=1>")
	
		
	Call_Module("ValidaPlaca");
		
end

function ValidaPlaca()

	get = loadstring(GET)()
	op = get["OPERATION"]
		
	placa1 = get["PLACA"]
	if (placa1:match("%u%u%u%d%d%d%d")) then 
		Modo_pto() 
	else
		ErroPlaca()
	end	
end

function ErroPlaca()
	
	ImagemTela(IMG_BG, 0, 0, 1)
	
	TxtTela(NOME_PLACA, "<BR><BR><BR>       ERRO NA PLACA ")
	echo ("<DELAY TIME=2>")
	
	LerPlaca()
	
end	

----------------------------------------------------------------------------------------
function Modo_pto()
	
	echo ("<GET TYPE=HIDDEN NAME=PLACA VALUE="..placa1..">")
	echo ("<GET TYPE=HIDDEN NAME=OPERATION VALUE="..op..">")
	
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	
	TrataCache()
	
	TxtTela(NOME_PTO, "<BR><BR>   Valor a Pagar: R$"..TicketPrice.."")
	
	ImagemTela(IMG_PTO_1, 17, 145, NAO_LIMPA)
	ImagemTela(IMG_PTO_2, 126, 145, NAO_LIMPA)
	ImagemTela(IMG_PTO_3, 17, 204, NAO_LIMPA)
	ImagemTela(IMG_PTO_4, 126, 204, NAO_LIMPA)
	

	echo ("<RECTANGLE NAME=DINHEIRO X=17  Y=145 WIDTH=97 HEIGHT=45 VISIBLE=0>")
	echo ("<CAPTURE NAME=PAYMENT>")
	echo ("<GET TYPE=TOUCH>")
	--echo ("<GET TYPE=SPECIALKEY>")
	echo ("</CAPTURE>")
	
	Call_Module("Confirma");
	
	
end

function EnviaServidor()
	
	get = loadstring(GET)()
	placa = get["PLACA"]
	pay = get["PAYMENT"]
	operation = get["OPERATION"]
	
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	
	TxtTela("<BR><BR><BR><BR>       Enviando Dados", "<BR><BR><BR><BR>         Aguardando<BR>    Resposta do Servidor")
	
	TrataCache()
	GetLogin()
	
	echo ("<GET TYPE=HIDDEN NAME=Operation VALUE="..operation..">")
	
	echo ("<GET TYPE=HIDDEN NAME=chIdentityName VALUE="..IdentityName..">")
	echo ("<GET TYPE=HIDDEN NAME=chIdentityType VALUE="..IdentityType..">")
	echo ("<GET TYPE=HIDDEN NAME=chIdentityId VALUE="..IdentityId..">")
	echo ("<GET TYPE=HIDDEN NAME=chUsername VALUE="..Username..">")
	echo ("<GET TYPE=HIDDEN NAME=chPIN VALUE="..PIN..">")
	echo ("<GET TYPE=HIDDEN NAME=chPosDeviceId VALUE="..PosDeviceId..">")
	echo ("<GET TYPE=HIDDEN NAME=chPosDeviceHardwareUniqueId VALUE="..PosDeviceHardwareUniqueId..">")
	echo ("<GET TYPE=HIDDEN NAME=chShopName VALUE="..ShopName..">")
	echo ("<GET TYPE=HIDDEN NAME=chTicketPrice VALUE="..TicketPrice..">")
	echo ("<GET TYPE=HIDDEN NAME=chPriceOfFineCancellation VALUE="..PriceOfFineCancellation..">")
	echo ("<GET TYPE=HIDDEN NAME=chServiceBaseUrl VALUE="..ServiceBaseUrl..">")
	
	echo ("<GET TYPE=SERIALNO NAME=PosSerial>")
	echo ("<GET TYPE=HIDDEN NAME=VehiclePlate VALUE="..placa..">")
	--echo ("<GET TYPE=VALUE NAME=PaidAmount SIZE=6 COL=9 LIN=11>")
	echo ("<GET TYPE=HIDDEN NAME=Username VALUE="..usu..">")
	echo ("<GET TYPE=HIDDEN NAME=PIN VALUE="..pass..">")
	
	echo ("<GET TYPE=HIDDEN NAME=PaymentMethod  VALUE="..pay..">")
	
	echo ("<GET TYPE=HIDDEN NAME=Funcao VALUE=Inicio>")
	
	echo ("<POST>")
	--RecebeServidor()----------------------
	
end

function CacheDesatualizado()
	
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	TxtTela(NOME_SEM_CACHE, "<BR><BR><BR>   Atualizar Agora?")
	
	ImagemTela(IMG_CON_YES, 17, 220, NAO_LIMPA)
	ImagemTela(IMG_CON_NO, 126, 220, NAO_LIMPA)
	
	echo ("<RECTANGLE NAME=SIM X=17  Y=220 WIDTH=97 HEIGHT=45 VISIBLE=0>")
	echo ("<RECTANGLE NAME=NAO X=126  Y=220 WIDTH=97 HEIGHT=45 VISIBLE=0>")
	echo ("<CAPTURE NAME=ATU>")
	echo ("<GET TYPE=TOUCH>")
	echo ("<GET TYPE=FIELD SIZE=1 COL=9 LIN=21 NOENTER=1>")
	echo ("</CAPTURE>")
	
	Call_Module("AtualizaCacheAgora")	
end

function AtualizaCacheAgora()
	
	get = loadstring(GET)()
	atu = get["ATU"]
	
	if(atu=="SIM") then 
		AtualizaCache() 
	elseif(atu == "9") then
		TrocaLogin()
	end
	Inicio()
end

function Confirma()

	get = loadstring(GET)()
	placa = get["PLACA"]
	pay = get["PAYMENT"]
	operation = get["OPERATION"]
		
	TrataCache()
	
	echo ("<GET TYPE=HIDDEN NAME=OPERATION VALUE="..operation..">")
	echo ("<GET TYPE=HIDDEN NAME=PLACA VALUE="..placa..">")
	--echo ("<GET TYPE=HIDDEN NAME=chTicketPrice VALUE="..TicketPrice..">")
	echo ("<GET TYPE=HIDDEN NAME=PAYMENT VALUE="..pay..">")
	
	
	
	ImagemTela(IMG_BG, 0, 0, LIMPA)
	
	TxtTela( NOME_PTO, "<BR><BR><BR>",
			" Operacao..: "..operation.."", "<BR>",
			" Zona......: Zona Teste", "<BR>",
			" Tarifa....: "..TicketPrice.."", "<BR>",
			" Placa.....: "..placa.."", "<BR>",
			" Met. Pagt.: "..pay.."", "<BR>",
			" Valor.....: "..TicketPrice.."")
	
	ImagemTela(IMG_CON_YES, 17, 220, NAO_LIMPA)
	ImagemTela(IMG_CON_NO, 126, 220, NAO_LIMPA)
	
	echo ("<RECTANGLE NAME=SIM X=17  Y=220 WIDTH=97 HEIGHT=45 VISIBLE=0>")
	echo ("<RECTANGLE NAME=NAO X=126  Y=220 WIDTH=97 HEIGHT=45 VISIBLE=0>")
	echo ("<CAPTURE NAME=IMP>")
	echo ("<GET TYPE=TOUCH>")
	--echo ("<GET TYPE=SPECIALKEY>")
	echo ("</CAPTURE>")
	
	Call_Module("RspConfirma")
	--EnviaServidor()
	
end

function RspConfirma()

	get = loadstring(GET)()
	imp = get["IMP"]
	placa = get["PLACA"]
	pay = get["PAYMENT"]
	operation = get["OPERATION"]
	
	echo ("<GET TYPE=HIDDEN NAME=OPERATION VALUE="..operation..">")
	echo ("<GET TYPE=HIDDEN NAME=PLACA VALUE="..placa..">")
	echo ("<GET TYPE=HIDDEN NAME=PAYMENT VALUE="..pay..">")
	
	if(imp == "SIM") then
		EnviaServidor()
	else
		Inicio()
	end
	
end
